package com.joolun.web.controller.goods;

import java.util.List;

import com.joolun.common.annotation.Anonymous;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.mall.entity.ProductRating;
import com.joolun.mall.service.IProductRatingService;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 商品评分Controller
 * 
 * @author joolun
 * @date 2025-04-12
 */
@RestController
@Anonymous
@RequestMapping("/goodsJudge/goodsRating")
public class ProductRatingController extends BaseController
{
    @Autowired
    private IProductRatingService productRatingService;

    /**
     * 查询商品评分列表
     */
    @PreAuthorize("@ss.hasPermi('goodsJudge:goodsRating:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductRating productRating)
    {
        startPage();
        List<ProductRating> list = productRatingService.selectProductRatingList(productRating);
        return getDataTable(list);
    }

    /**
     * 导出商品评分列表
     */
    @Log(title = "商品评分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductRating productRating)
    {
        List<ProductRating> list = productRatingService.selectProductRatingList(productRating);
        ExcelUtil<ProductRating> util = new ExcelUtil<ProductRating>(ProductRating.class);
        util.exportExcel(response, list, "商品评分数据");
    }

    /**
     * 获取商品评分详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String productId)
    {
        return success(productRatingService.selectProductRatingById(productId));
    }

    /**
     * 新增商品评分
     */
    @Log(title = "商品评分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ProductRating productRating)
    {
        return toAjax(productRatingService.insertProductRating(productRating));
    }

    /**
     * 修改商品评分
     */
    @PreAuthorize("@ss.hasPermi('goodsJudge:goodsRating:edit')")
    @Log(title = "商品评分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductRating productRating)
    {
        return toAjax(productRatingService.updateProductRating(productRating));
    }

    /**
     * 删除商品评分
     */
    @PreAuthorize("@ss.hasPermi('goodsJudge:goodsRating:remove')")
    @Log(title = "商品评分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productRatingService.deleteProductRatingByIds(ids));
    }
}
